package com.zryc.shop.oms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zryc.shop.oms.entity.OrderReturnApply;
import com.zryc.shop.oms.mapper.OrderReturnApplyMapper;
import com.zryc.shop.oms.service.IOrderReturnApplyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zryc.shop.ums.entity.Menu;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * <p>
 * 订单退货申请 服务实现类
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@Service
public class OrderReturnApplyServiceImpl extends ServiceImpl<OrderReturnApplyMapper, OrderReturnApply> implements IOrderReturnApplyService {

    /**
     * 分页查询列表
     *
     * @param pageNum
     * @param pageSize
     * @param id
     * @param status
     * @param createTime
     * @param handleMan
     * @param handleTime
     * @return
     */
    @Override
    public Page<OrderReturnApply> list(Integer pageNum, Integer pageSize, Integer id, Integer status,
                                       Date createTime, String handleMan, Date handleTime) {
        Page<OrderReturnApply> page = new Page<>(pageNum, pageSize);
        QueryWrapper<OrderReturnApply> wrapper = new QueryWrapper<>();

        if (!StringUtils.isEmpty(handleMan)) {
            wrapper.like("handle_man", handleMan);
        }

        if (id != null) {
            wrapper.eq("id", id);
        }

        if (status != null) {
            wrapper.eq("status", status);
        }

        if (createTime != null) {
            wrapper.eq("create_time", createTime);
        }

        if (handleTime != null) {
            wrapper.eq("handle_time", handleTime);
        }
        return page(page, wrapper);
    }

    /**
     * 修改状态
     *
     * @param id
     * @param returnApply
     * @return
     */
    @Override
    public Object updateStatus(Long id, OrderReturnApply returnApply) {
        Integer status = returnApply.getStatus();
        UpdateWrapper<OrderReturnApply> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", id);
        updateWrapper.set("status", status);
        update(updateWrapper);
        return "修改成功";
    }
}
